package com.xiaoyu.merchant.ui.activity.set;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ToggleButton;

import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.xiaoyu.commonlib.BillionCardConstants;
import com.xiaoyu.commonlib.ui.base.BaseActivityWithTitle;
import com.xiaoyu.commonlib.utils.PreferencesUtil;
import com.xiaoyu.merchant.R;
import com.xiaoyu.merchant.ui.activity.login.LoginActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SetActivity extends BaseActivityWithTitle implements CompoundButton.OnCheckedChangeListener {

    @BindView(R.id.set_activity_receive_trailer)
    ToggleButton mTogBtn;

    @Override
    protected void loadContentView(ViewGroup parent) {
        setTitleText("设置");
        View mView = LayoutInflater.from(this).inflate(R.layout.activity_set, parent, true);
        ButterKnife.bind(this);
        initView();
    }

    //初始化
    private void initView() {
        mTogBtn.setOnCheckedChangeListener(this);
        mTogBtn.setChecked(PreferencesUtil.getBoolean(PreferencesUtil.OPEN_MESSAGE, false));
    }


    //是否接收活动通知打开关闭状态
    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean ischecked) {
        if (mTogBtn.isChecked()) {//打开状态
            PreferencesUtil.commit(PreferencesUtil.OPEN_MESSAGE, ischecked);//保存打开状态
        } else {
            PreferencesUtil.commit(PreferencesUtil.OPEN_MESSAGE, ischecked);//保存关闭状态
        }
    }

    @OnClick(R.id.activity_set_login_out)
    public void loginOut() {
        //退出到登录页面
        if (PreferencesUtil.getInt(PreferencesUtil.LOGIN_TYPE, -1) == 2) {
            UMShareAPI.get(this).deleteOauth(this, SHARE_MEDIA.WEIXIN, null);
        }
        PreferencesUtil.clear();
        startActivity(new Intent(this, LoginActivity.class));
        sendBroadcast(new Intent(BillionCardConstants.MSG_LOG_OUT));
        finish();
    }

    //跳转意见反馈页面
    @OnClick(R.id.activity_set_feedback)
    public void feedBackClick() {
        startActivity(new Intent(this, FeedBackActivity.class));
    }

}
